package com.larosa.practice.domain;

import com.larosa.practice.fruitenum.Fruit;
import com.larosa.practice.strategy.StrawberryDiscountStrategy;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @Author: larosa
 * @Description: 第三个问题的测试类
 * @DateTime: 2025/2/9 11:21
 **/
@SpringBootTest
class SupermarketTest3 {
    /**
     *3.超市做促销活动，草莓限时打 8 折。现在顾客 C 在超市购买了若干斤苹果、 草莓和芒果，需计算一共需要多少钱？
     * 请编写函数，对于 C 购买的水果斤数 (水果斤数为大于等于 0 的整数)，计算并返回所购买商品的总价。
     * 这个问题会用到草莓的折扣策略
     */
    @Test
    public void testC() {
        //买苹果2斤，草莓3斤，芒果1斤  2*8 + 3*13*0.8 + 1*20 = 67.2
        Supermarket supermarket = new Supermarket(new StrawberryDiscountStrategy());
        int appleQuantity = 2;
        int strawberryQuantity = 3;
        int mangoQuantity = 1;
        BigDecimal appleTotal = Fruit.APPLE.getPrice().multiply(BigDecimal.valueOf(appleQuantity));
        BigDecimal strawberryTotal = Fruit.STRAWBERRY.getPrice().multiply(BigDecimal.valueOf(strawberryQuantity)).multiply(new BigDecimal("0.8"));
        BigDecimal mangoTotal = Fruit.MANGO.getPrice().multiply(BigDecimal.valueOf(mangoQuantity));
        BigDecimal expected = appleTotal.add(strawberryTotal).add(mangoTotal);
        System.out.println("预期花费：" + expected + "元");
        BigDecimal actual = supermarket.calculateTotalPrice(appleQuantity, strawberryQuantity, mangoQuantity);
        System.out.println("实际花费：" + actual + "元");
        assertEquals(expected, actual);
    }

}